package zconvert

import (
	"strings"
	"venus/util/ztype"
)

/* ----- list<number> -> list<number> ----- */

func ListNumberToListNumber[T1 ztype.UtNumber, T2 ztype.UtNumber](in []T1) (out []T2) {
	for _, t1 := range in {
		out = append(out, T2(t1))
	}
	return
}

/* ----- list<string> -> list<number> ----- */

func ListStrToListNumber[T ztype.UtNumber](list []string) []T {
	result := make([]T, 0)
	for _, v := range list {
		result = append(result, T(ToInt64(v)))
	}
	return result
}
func ListStrToListInt(list []string) []int {
	result := make([]int, 0)
	for _, v := range list {
		result = append(result, ToInt(v))
	}
	return result
}
func ListStrToListInt32(list []string) []int32 {
	result := make([]int32, 0)
	for _, v := range list {
		result = append(result, ToInt32(v))
	}
	return result
}
func ListStrToListInt64(list []string) []int64 {
	result := make([]int64, 0)
	for _, v := range list {
		result = append(result, ToInt64(v))
	}
	return result
}

/* ----- string -> list<number> ----- */

func ToListStr(str string, sep string) []string {
	return strings.Split(str, sep)
}
func ToListNumber[T ztype.UtNumber](str string, sep string) []T {
	return ListStrToListNumber[T](strings.Split(str, sep))
}
func ToListInt(str string, sep string) []int {
	return ListStrToListInt(strings.Split(str, sep))
}
func ToListInt32(str string, sep string) []int32 {
	return ListStrToListInt32(strings.Split(str, sep))
}

/* ----- string -> list<list<number>> ----- */

func ToListListStr(str string, sep1, sep2 string) [][]string {
	result := make([][]string, 0)
	list1 := strings.Split(str, sep1)
	for _, v := range list1 {
		list2 := strings.Split(v, sep2)
		result = append(result, list2)
	}
	return result
}
func ToListListNumber[T ztype.UtNumber](str string, sep1, sep2 string) [][]T {
	result := make([][]T, 0)
	list1 := strings.Split(str, sep1)
	for _, v := range list1 {
		list2 := strings.Split(v, sep2)
		result = append(result, ListStrToListNumber[T](list2))
	}
	return result
}
func ToListListInt(str string, sep1, sep2 string) [][]int {
	result := make([][]int, 0)
	list1 := strings.Split(str, sep1)
	for _, v := range list1 {
		list2 := strings.Split(v, sep2)
		result = append(result, ListStrToListInt(list2))
	}
	return result
}
func ToListListInt32(str string, sep1, sep2 string) [][]int32 {
	result := make([][]int32, 0)
	list1 := strings.Split(str, sep1)
	for _, v := range list1 {
		list2 := strings.Split(v, sep2)
		result = append(result, ListStrToListInt32(list2))
	}
	return result
}
func ToListListInt64(str string, sep1, sep2 string) [][]int64 {
	result := make([][]int64, 0)
	list1 := strings.Split(str, sep1)
	for _, v := range list1 {
		list2 := strings.Split(v, sep2)
		result = append(result, ListStrToListInt64(list2))
	}
	return result
}
